<?php

    /**
     *      [Discuz!] (C)2001-2099 Comsenz Inc.
     *      This is NOT a freeware, use is subject to license terms
     *      $Id: table_mobile_setting.php 31281 2012-08-03 02:29:27Z zhangjie $
     */

    if (!defined('IN_DISCUZ')) {
        exit('Access Denied');
    }

    class table_cloud_spotsign extends discuz_table {

        public function __construct() {
            $this->_table = 'cloud_spotsign';
            $this->_pk = 'id';

            parent::__construct();
        }

        //判断记录是否存在
        public function check_product_exist($uuid, $spotid) {
            return DB::fetch_first("SELECT * FROM ".DB::table($this->_table)." WHERE uuid='".$uuid."' AND spotid=".$spotid);
        }

        //插入数据库
        public function insert($arr) {
            return DB::insert($this->_table, $arr, true);
        }

        //更新数据库
        public function update($caid, $data) {
            $caid = intval($caid);
            if (!$data) {
                return;
            }
            return DB::update($this->_table, $data, DB::field($this->_pk, $caid));
        }

        //查找某条记录
        public function fetch_info($id) {
            $id = intval($id);
            return DB::fetch_first("SELECT * FROM %t WHERE id=%d", array($this->_table, $id));
        }

        //查询所有limt数据
        public function fetch_all_limit($uuid) {
//            if(empty($uuid)){
//                $where = '1=1';
//            }else{
                $where= " uuid='".$uuid."'";
//            }
            return DB::fetch_all('SELECT * FROM ' . DB::table($this->_table) . ' where '.$where);
        }
        //查询所有limt数据
        public function fetch_all_limit_pages($start = 0, $limit = 0) {
            return DB::fetch_all('SELECT * FROM ' . DB::table($this->_table) . '  order by ' . DB::order('lasttime', 'desc') . DB::limit($start, $limit));
        }
        //查询所有count数据
        public function fetch_all_count() {
            return DB::fetch_first('SELECT count(id) as count FROM ' . DB::table($this->_table));
        }

        //查询所有limt数据
        public function fetch_all_by_user_limit($userId,$cadid, $start = 0, $limit = 0) {
            return DB::fetch_all('SELECT * FROM ' . DB::table($this->_table) . ' where cuid = ' . $userId . ' and cadid = '.$cadid.' order by ' . DB::order('collecttime', 'desc') . DB::limit($start, $limit));
        }

        //查询所有limt数据
        public function fetch_all_by_user($userId,$cadid) {
            return DB::fetch_all('SELECT * FROM ' . DB::table($this->_table) . ' where cuid = ' . $userId . ' and cadid = '.$cadid.' order by ' . DB::order('collecttime', 'desc') );
        }

        //根据keys称查询
        public function fetch_collect_by_cpid($cpid, $cuid) {
            return DB::fetch_first('SELECT * FROM ' . DB::table($this->_table) . ' WHERE cpid =' . $cpid . ' AND cuid=' . $cuid);
        }

        //根据keys称查询
        public function fetch_collect_by_name($name, $cuid) {
            return DB::fetch_all("SELECT * FROM " . DB::table($this->_table) . " WHERE pname like '%" . $name . "%' AND cuid=" . $cuid);
        }


        // 删除
        public function delete_by_id($id) {
            return DB::query("DELETE FROM %t WHERE id=%d", array($this->_table, $id));
        }


    }